<?php
namespace Core\Common\Component\Cache;

use Core\Common\Helper\Reg;
use Illuminate\Support\Arr;
use Core\Common\Base\Config;

class Cache
{
    /**
     * 获取缓存实例
     * @param string $name
     * @return CacheStore
     */
    public static function store($name='default')
    {
        $key = "cache.{$name}";
        if ($ins = Reg::get($key)) {
            return $ins;
        }

        $configs = Config::config("cache.{$name}");
        $driver = Arr::get($configs, "driver");
        $ins = null;

        if ($driver == 'redis') {
            $ins = new RedisStore($configs);
        }

        Reg::set($key, $ins);
        return $ins;
    }
}